﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.iot.core.exception
{
    public class MyExceptionUtil
    {
        public static string GetMsg(Exception ex)
        {
            if (ex == null)
            {
                return "";
            }
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }
            return ex.Message ?? "";    
        }
        public static string GetFullmsg(Exception ex)
        {
            var sb = new StringBuilder();
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }
            if (!string.IsNullOrEmpty(ex.Message))
            {
                sb.Append(ex.Message);
            }
            sb.Append(ex.StackTrace);
            return sb.ToString();
        }
        public static string GetExClsname(Exception ex)
        {
            if (ex == null)
            {
                return "";
            }
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }
            var r = ex.GetType().FullName;
            if (r.Length > 50)
            {
                r = r.Substring(0, 50);
            } 
            return r;
        }
        public static string GetExMsg(Exception ex)
        {
            if (ex == null)
            {
                return "";
            }
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }
            var r = ex.Message??"";
            if (r.Length > 200)
            {
                r = r.Substring(0, 200);
            }
            return r;
        }
    }
}
